package com.example.replacebooks.controller;

import com.example.replacebooks.common.Result;
import com.example.replacebooks.entity.Class;
import com.example.replacebooks.entity.Message;
import com.example.replacebooks.entity.Params;
import com.example.replacebooks.service.ClassService;
import com.example.replacebooks.service.MessageService;
import com.github.pagehelper.PageInfo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@CrossOrigin //解决跨域问题
@RestController
@RequestMapping("/message")
public class MessageController {

    private static final Logger log = LoggerFactory.getLogger(MessageController.class);

    @Resource
    private MessageService messageService;

    @GetMapping
    public Result findAll(){return Result.success(messageService.findAll());}

    // 消息信息获取
    @GetMapping("/search")
    public Result findBySearch(Params params){
        PageInfo<Message> info = messageService.findBySearch(params);
        return Result.success(info);
    }

    // 未读消息信息获取
    @GetMapping("/searchByread")
    public Result findBySearchByread(Params params){
        PageInfo<Message> info = messageService.findBySearchByread(params);
        return Result.success(info);
    }

    // 信息更新
    @PostMapping("/updatebymessageid")
    public Result add(@RequestBody Message message){
        messageService.updateByMessageid(message);
        return Result.success();
    }

    // 回复信息添加
    @PostMapping("/replyadd")
    public Result replyadd(@RequestBody Message message){
        messageService.replyadd(message);
        return Result.success();
    }

    // 留言信息添加
    @PostMapping("/leaveadd")
    public Result leaveadd(@RequestBody Message message){
        messageService.leaveadd(message);
        return Result.success();
    }

    // 评价信息添加
    @PostMapping("/evaluateadd")
    public Result evaluateadd(@RequestBody Message message){
        messageService.evaluateadd(message);
        return Result.success();
    }

    @DeleteMapping("/{messageid}")
    public Result delete(@PathVariable Integer messageid){
        messageService.delete(messageid);
        return Result.success();
    }
}
